import { PrivacyConfig } from "@/config/PrivacyConfig";
import { Logger } from "@/utils/Logger";
import { RandomUtil } from "@/utils/RandomUtil";

export class RoleModel {


    public id: number;
    public roleName: string;
    public remarks: string = "" //备注
    public privacyIdList: Array<number> = [];

    public static modelList: Array<RoleModel> = [];

    public static totalNum: number = 10;

    public static initTest() {
        this.modelList = [];
        let privacyList: Array<PrivacyConfig> = []
        PrivacyConfig.configMap.forEach((value: PrivacyConfig, key: number) => {
            privacyList.push(value);
        });

        for (let i = 0; i < this.totalNum; i++) {
            let model: RoleModel = new RoleModel();
            model.id = i;
            model.roleName = "role" + i;
            model.remarks = "remarkd" + i
            let randomtemp: Array<PrivacyConfig> = RandomUtil.randomArr(privacyList, RandomUtil.nextInt(0, privacyList.length));
            for (let j = 0; j < randomtemp.length; j++) {
                model.privacyIdList[j] = randomtemp[j].id;
            }
            this.modelList[i] = model;
        }
        // Logger.log("RoleModel.initTest", privacyList, this.modelList)
    }

    public static getRoleModel(roleId: number) {
        for (let i = 0; i < this.modelList.length; i++) {
            let model: RoleModel = this.modelList[i];
            if (model.id == roleId) {
                return model;
            }
        }
    }

    public static getShowList(callback: Function) {
        let showList: Array<RoleModel> = [];
        // HttpClient.queryServerList(listQuery["page"], listQuery["limit"], () => {
        showList = this.modelList
        Logger.log("RoleModel.getShowList", showList)
        callback && callback(showList);
        // })

    }

}